package com.yupfeg.test.share

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.yupfeg.livedata.R
import com.yupfeg.test.app.AppShareViewModel
import com.yupfeg.test.base.activityViewModelDelegate
import com.yupfeg.test.base.applicationViewModelDelegate

/**
 * 发送事件的Fragment
 * @author yuPFeG
 * @date 2021/09/19
 */
class SenderFragment : Fragment(){

    private val mActivitySharedViewModel : FragmentSharedViewModel by activityViewModelDelegate()
    private val mAppSharedViewModel : AppShareViewModel by applicationViewModelDelegate()

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_sender,container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        view.findViewById<TextView>(R.id.btn_sender_single_event).setOnClickListener{
            mActivitySharedViewModel.sendSingleEvent()
        }

        view.findViewById<View>(R.id.btn_sender_single_state).setOnClickListener {
            mActivitySharedViewModel.getTestStateData()
        }

        view.findViewById<View>(R.id.btn_sender_error_state).setOnClickListener{
            mActivitySharedViewModel.getTestDataError()
        }

        view.findViewById<View>(R.id.btn_sender_app_share_event).setOnClickListener {
            mAppSharedViewModel.sendForeverLifecycleEvent()
        }
    }
}